package JiHeDemo.collections;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author 86150
 */
public class Collection {
	public static void main(String[] args) {
		List<Integer> list = new ArrayList<Integer>();
		list.add(2);
		list.add(4);
		list.add(1);
		list.add(6);
		list.add(3);
		System.out.println("排序之前：" + list);
		Collections.sort(list);//进行排序
		System.out.println("排序之后：" + list);

		//二分查找
		int a = Collections.binarySearch(list, 1);
		System.out.println("查找结果：" + a);

		//复制
		List<Integer> dest = new ArrayList<Integer>();
		//复制之前两个数组元素相等
		for (int i = 0; i < list.size(); i++) {
			dest.add(0);
		}
		//然后进行复制
		Collections.copy(dest, list);
		System.out.println(dest);


		//reverse 对数组进行反转
		System.out.println("反转之前:" + list);
		Collections.reverse(list);//反转
		System.out.println("反转之后:" + list);

		//打乱重新洗牌   shuffle
		Collections.shuffle(list);
		System.out.println("打乱之后:" + list);

		//list转数组
		System.out.println("--------------list转数组-------------");
		Integer[] arr = list.toArray(new Integer[0]);
		System.out.println("arr长度：" + arr.length);
		System.out.println("转成数组之后：" + Arrays.toString(arr));


		//数组转集合
		System.out.println("--------------数组转集合-------------");
		Integer[] arrs = {1, 2, 3, 4, 5, 6};
		List<Integer> arrss = Arrays.asList(arrs);
		System.out.println(arrss);
	}
}
